<template>
	<view class="location">
		<view class="location_info">
			<view class="location_info_people">
				<span>收件人</span><input v-model="GitList.realName" />
			</view>
			<view class="location_info_people">
				<span>手机号</span><input v-model="GitList.phone" />
			</view>
			<view class="location_info_people" @click="ClickLocation()">
				<span>所在地区</span><input disabled v-model="GitList.provinceCityDistrict" />
			</view>
			<view class="location_info_people">
				<span>详细地址</span><input v-model="GitList.detail" />
			</view>
			<!-- <view class="location_info_people">
				<span>邮政编码</span><input v-model="GitList.postCode" />
			</view> -->

		</view>
		<view class="mr_scope">
			<span>设为默认地址</span>
			<u-switch v-model="CheckValue" activeColor="#88A58A" @change="change"></u-switch>
		</view>
		<u-popup :show="show" @close="close()">
			<view class="info">
				<scroll-view class="scroll" scroll-y="true">
					<view v-for="item in columns" @click="clickCname(item)" class="scroll_view">
						{{item.cname}}
					</view>
				</scroll-view>
			</view>
		</u-popup>
		<u-button type="success" shape="circle" text="保存" @click="Getlocation()"></u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				locationL: '',
				columns: [],
				show: false,
				tabTitle: ['请选择'],
				locationValue: '',
				CheckValue: false,
				GitList: {
					realName: '',
					phone: '',
					provinceCityDistrict: '',
					detail: '',
					isDefault: 0
				}
			}
		},
		methods: {
			Getlocation() {
				let regExp = new RegExp("^[0-9]{11}$")
				if (!regExp.test(this.GitList.phone)) {
					uni.showToast({
						title: '手机号格式错误',
						icon: 'error'
					})
				} else if (this.GitList.phone == '') {
					uni.showToast({
						title: '必须填写手机号',
						icon: 'error'
					})
				} else if (this.GitList.detail == '') {
					uni.showToast({
						title: '必须填写详细地址',
						icon: 'error'
					})
				} else if (this.GitList.realName == '') {
					uni.showToast({
						title: '必须填写收货人',
						icon: 'error'
					})
				} else if (this.GitList.provinceCityDistrict == '') {
					uni.showToast({
						title: '必须选择所在地区',
						icon: 'error'
					})
				} else {
					this.$http({
						url: '/crmUserAddress/insCrmUserAddress',
						data: this.GitList
					}).then(res => {
						if (res.data.code === 200) {
							uni.navigateBack()
						} else {
							uni.showToast({
								title: '保存失败',
								icon: 'error'
							})
						}
					})
				}
			},
			change(e) {
				if (e === true) {
					this.GitList.isDefault = 1
				} else {
					this.GitList.isDefault = 0
				}
			},
			clickCname(item) {
				this.GitList.provinceCityDistrict = this.GitList.provinceCityDistrict + item.cname
				this.SearchLocation(item.id)
				this.GitList.cityId = item.id
			},
			SearchLocation(id) {
				this.$http({
					url: '/area/selectArea',
					method: 'GET',
					data: {
						parentId: id,
					}
				}).then(res => {
					this.columns = res.data.data
					if (this.columns.length == 0) {
						this.show = false
					}
				})
			},
			ClickLocation() {
				this.show = true
				this.GitList.provinceCityDistrict = ''
				this.SearchLocation(1)
			},
			close() {
				this.show = false
			},
		},
		onLoad() {
			this.SearchLocation(1)

		}
	}
</script>

<style>
	@import './index';
</style>
